home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol260 / boostref.arc / BOREF1.WS next >
Encoding:
Text File  |  1986-09-24  |  42.5 KB  |  1,197 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.                       Boosters Users Guide
  12.                        by George F. Smith
  13.  
  14.  
  15.                       609 Candlewick Lane
  16.                        Lilburn, GA 30247
  17.                         (404) 923-6879
  18.  
  19.  
  20.                          November, 1985
  21.                           Version 1.0
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.              (C) Copyright 1985 by George F. Smith
  36.                       All Rights Reserved
  37. .pa
  38. è.F1Boosters Users Guide                                Page #
  39.                       BOOSTERS USERS GUIDE
  40.  
  41.                        Table of Contents
  42.  
  43.      Introduction 
  44.         What is Boosters? .............................  3
  45.         Speed Without Snow ............................  5
  46.  
  47.      Section 1  Getting Started
  48.         What's On the Distribution Disk ...............  6
  49.         What to Do First--BACKUP ......................  7
  50.  
  51.      Section 2  Ground Rules
  52.         Some Notes On Video ...........................  8
  53.         Heap I/O ...................................... 10
  54.  
  55.      Section 3 Descriptions of Boosters Routines ...... 12
  56.         BoDecl declares ............................... 13
  57.         BoxUL procedure ............................... 14
  58.         Calendar procedure ............................ 16
  59.         Center function ............................... 17
  60.         Copies function ............................... 18
  61.         CopyBlk procedure ............................. 19
  62.         CopyStr function .............................. 21
  63.         Cursor procedures ............................. 22
  64.         Dows function ................................. 23
  65.         Exec procedure ................................ 24
  66.         FillHeap procedure ............................ 26
  67.         FindStr procedure ............................. 27
  68.         GetStr procedure .............................. 29
  69.         Left function ................................. 30
  70.         MoveBg procedure .............................. 31
  71.         MoveBlk procedure ............................. 33
  72.         NsOrbit procedure ............................. 34
  73.         OverStr function .............................. 35
  74.         PutStr procedure .............................. 36
  75.         RemBlk procedure .............................. 37
  76.         RestoreScreen procedure ....................... 40
  77.         Right function ................................ 38
  78.         Rword function ................................ 39
  79.         SaveScreen procedure .......................... 40
  80.         SetAtt procedure .............................. 41
  81.         Space function ................................ 42
  82.         Stime procedure ............................... 45
  83.         Strip function ................................ 43
  84.         Timer function ................................ 44
  85.         TimeXY procedure .............................. 45
  86.         Upper function ................................ 47
  87.         Wait procedure ................................ 48
  88.         Word function ................................. 49
  89.         WordInd function .............................. 50
  90.         Words function ................................ 51
  91. .pa
  92. è                            INTRODUCTION
  93.  
  94.  
  95.  
  96. This book is a reference guide for Turbo Pascal (tm) programmers ì
  97. using the Boosters Utilities (C) in their work.  It provides ì
  98. formats, descriptions, and tested coding examples for each Booster 
  99. routine.  
  100.  
  101. Boosters is intended for students, software developers, hobbyists, ì
  102. or consultants who have at least a working knowledge of Turbo 
  103. Pascal and who are targeting their products for IBM PC/compatible ì
  104. systems that run under MS-DOS 2.0 or higher.  All Boosters 
  105. routines will run under Turbo Pascal version 2.0 or 3.0, except 
  106. the Exec procedure, which requires version 3.0.  
  107.  
  108.  
  109.  
  110. WHAT IS BOOSTERS?
  111.  
  112. Boosters is a family of Turbo Pascal utilities tuned for speed of 
  113. execution and ease of use.  Their evolution is as follows: 
  114.  
  115. While developing a large program with Turbo Pascal, I found it ì
  116. convenient to write some string functions that had proved ì
  117. indispensible in my work with other languages.  These are ì
  118. functions familiar to most programmers--routines to center or ì
  119. justify text, for example.  Turbo Pascal's features made it ì
  120. extremely easy to write them in source code.  As an example, the ì
  121. function Copies, which generates a string of length N of character ì
  122. C, can be expressed as: ì
  123. ì
  124.           Function COPIES ( C : Char; 
  125.                             N : LenType        (* 1..255  *)ì
  126.                                 ) : AnyString  (* string[255]  *)
  127.           var
  128.              S : AnyString;  ì
  129.              L : Integer absolute S;
  130.           beginì
  131.              L := N;ì
  132.              FillChar ( S[1], N, C );ì
  133.              Copies := Copy ( S, 1, N );ì
  134.           end; ì
  135. ì
  136. With the function thus defined, you can wring a great deal of ì
  137. work from it, such as marking the length of a user input field ì
  138. with a particular character and attribute:
  139. ì
  140.           GoToXY ( Xval, Yval );   (* Cursor at field beginning  *)ì
  141.           TextColor ( Yellow );    (* Brighten field  *)
  142.           Write ( Copies ( '_', Length(field) );  (* Mark field  *)ì
  143. .pa
  144. èThe preceding example works fine, but lacks the convenience and ì
  145. speed desired when used repeatedly.  Seeking to combine the ì
  146. operations of those three procedures into one, and add a few ì
  147. enhancements, I wrote a routine called PutStr ("Put String") which 
  148. has the following declaration: ì
  149.  
  150.           Procedure PUTSTR ( D : Char;         (* Direction  *) 
  151.                              S : AnyString;    (* string[255]  *)
  152.                              X : ColumnType;   (* 1..80  *)
  153.                              Y : RowType;      (* 1..25  *)
  154.                              A : Integer ); ì
  155. ì
  156. PutStr writes string S directly to video memory beginning at ì
  157. location X,Y for length Length(S) with display attribute A.  The ì
  158. value of 'D' tells PutStr whether to proceed horizontally or
  159. vertically.
  160. ì
  161. Since S is defined as a value parameter, it allows for the direct ì
  162. placement of function calls in the PutStr procedure statement.    ì
  163.  
  164. Applying PutStr to the last example, we get:
  165.  
  166.           PutStr ( h, Copie≤ ('_', length(field), Xval, Yval, 14);ì
  167. ì
  168. Because PutStr bypasses DOS and BIOS video I/O services and goes ì
  169. directly to screen memory, PutStr is faster than the standard ì
  170. procedure Write.  ì
  171.  
  172. Copies and PutStr became part of a growing collection of routines ì
  173. that performed frequently used string and video operations.  For ì
  174. casual use, they were more than adequate in their source-level ì
  175. form.  But for large programming efforts, especially ones that ì
  176. employed time-critical operations, I felt compelled to tighten ì
  177. every routine to its limit.  Using the existing collection as ì
  178. prototypes, I began rewriting them in 8088 assembly language.  ì
  179.  
  180. The finished product--a collection of about 12 routines--was the 
  181. original Boosters.  
  182. .pa
  183. èSPEED WITHOUT SNOW 
  184.  
  185. From long association with the winters of Buffalo, New York, I ì
  186. have concluded that snow has very limited appeal.  Unfortunately, ì
  187. on systems running with the IBM Color Graphics Adapter (tm), ì
  188. direct accesses to video memory will produce quick bursts of 
  189. "snow."  The IBM Technical Reference Manual (2.02) describes it 
  190. this way: 
  191.  
  192.         The processor and the display control unit have 
  193.         equal access to the display buffer during all the 
  194.         operating modes, except the high-resolution 
  195.         alphanumeric mode.  During this mode, the processor 
  196.         should access the display buffer during the vertical 
  197.         retrace time.  If it does not, the display will be 
  198.         affected with random patterns . . . (p 1-146) 
  199.  
  200. Programs that do direct video I/O only during vertical retrace 
  201. will indeed avoid all snow affects.  They will also avoid much of 
  202. the speed gained from using the direct I/O technique, unless the 
  203. amount of text written is slight.  When reading or writing a full 
  204. screen's worth of text, the loss of speed is painfully noticable 
  205. if programs wait for vertical retrace before performing I/O 
  206. operations.  ì
  207.  
  208. All is not grim, however.  Boosters makes it easy for Turbo 
  209. Pascal programmers to build screens on the heap, then display 
  210. them almost instantly, without snow, on a color display (or, of 
  211. course, a monochrome display).  Please see the section on Heap I/O 
  212. for details.  
  213.  
  214. The Boosters demo program, BoDemo, uses Heap I/O techniques to 
  215. move large amounts of data to and from the screen.  
  216.  
  217.  
  218. BOOSTERS PRODUCTION RELEASE
  219.  
  220. Heap I/O support is a major component of Boosters' Special-
  221. Purpose section.  Other notable members of this group include 
  222. Exec, which allows programs to call other programs as if they 
  223. were procedures, and Timer, which can add time-controlled 
  224. processing to your programs.  
  225.  
  226. The addition of the special-purpose routines to the original 
  227. string and video group make up the production release of 
  228. Boosters--43 routines in all.  
  229.  
  230. As a supplement to the technical descriptions of Section 3, 
  231. please refer to the Boosters demo program, BoDemo, and to the 
  232. individual example programs included on the distribution 
  233. diskette.  
  234. .pa 
  235. è                      SECTION 1 - GETTING STARTED
  236.  
  237.  
  238.  
  239. WHAT'S ON THE DISTRIBUTION DISKETTE
  240.  
  241. The diskette you received with your Boosters order contains ì
  242. files that are classified as follows:ì
  243. ì
  244.      (A)  The complete collection of the Boosters routines, ì
  245.           contained in a file named Boosters.pas.
  246.  
  247.      (B)  The above collection split into files for each 
  248.           Booster function and procedure.  The Exec 
  249.           procedure, for example, resides on a file named
  250.           Exec.pas; the Upper function can be found on
  251.           Upper.pas--and so on.
  252. ì
  253.      (C)  A file of variable, type, and constant declarations
  254.           that Boosters needs to run--named BoDecl.pas.
  255.  
  256.      (D)  .COM files needed for the external procedures.
  257. ì
  258.      (E)  A program that demonstrates Boosters, BoDemo.pas and
  259.           BoDemo.com.  These programs perform the same exceptì
  260.           for the Exec procedure, which will only run from 
  261.           BoDemo.com under Turbo Pascal Version 3.0.  (The Exec
  262.           call is commented out in the .pas version.)
  263.  
  264.      (F)  Small programs illustrating how each Boosters routine
  265.           works.  All were tested, saved, then copied directly
  266.           to the appropriate example sections of this Users Guide
  267.           to ensure reproduction integrity.
  268.  
  269.      (G)  Source files for the Boosters assembler routines.  
  270.           Due to directory space limitations, the assembler
  271.           source files are stored in a subdirectory named
  272.           BoAsm.
  273.  
  274. There are over 115 files on the distribution diskette.
  275. .pa
  276. è                      SECTION 1 - GETTING STARTED    
  277.  
  278.  
  279. WHAT TO DO FIRST--BACKUP
  280.  
  281. The distribution diskette is not copy-protected, so either ì
  282. DiskCopy or Copy will work fine.  Copy the original diskette and ì
  283. put it safely away.  ì
  284.  
  285. You will probably find it most convenient to keep Boosters right ì
  286. with Turbo Pascal--on the same diskette or subdirectory.  At a 
  287. minimum, copy Boosters.pas, BoDecl.pas, and the Boosters .com 
  288. files.  If there is sufficient disk space for the individual ì
  289. routines (category B above), we recommend you transfer those as 
  290. well.  ì
  291.  
  292. ì
  293.      Note: The Exec procedure requires that a copy of ì
  294.            Command.com (version 2.0 or higher) be present on ì
  295.            the default disk drive.  The Command processor ì
  296.            loads and passes control to the program you 
  297.            choose to execute.  ì
  298.  
  299. ì
  300. Having backed up your distribution diskette and copied Boosters to ì
  301. a convenient working location, fire up the demo program, ì
  302. BoDemo.com, and let it run for awhile.  Working examples are a 
  303. great benefit to understanding.  You may find it convenient to 
  304. clone parts of BoDemo.pas for your own programs.  
  305. .pa
  306. è                       SECTION 2 - GROUND RULES
  307.  
  308.  
  309.  
  310. SOME NOTES ON VIDEO
  311.  
  312. Since Boosters addresses video memory frequently, it might be ì
  313. helpful to cover a few basics about the display area.  
  314.  
  315. 1.  Boosters video operations assumes a screen size of 80 columns ì
  316. by 25 rows (80x25).  In keeping with standard notational ì
  317. conventions, (1,1) refers to the upper left corner of the screen ì
  318. or current window, while (80,25) references the lower right.  The 
  319. variable X refers to the column, Y to the row, so that for X = 30   ì
  320. and Y = 10, for instance, we mean column 30, row 10 (30,10). 
  321.  
  322. 2.  Boosters will run with the IBM Color/Graphics Adapter, theì
  323. the IBM Monochrome Adapter, the IBM Enhanced Graphics Adapter, and
  324. on most compatibles.  It was developed on a 256K Compaq.
  325.  
  326. 3.  Each character in video memory has an attribute byte, located ì
  327. at the next higher address, that controls how the character will ì
  328. be displayed.  For the Color/Graphics Adapter and compatibles, ì
  329. this attribute byte can blink, color, or intensify the character, 
  330. and can color the character background.  
  331.  
  332. Blinking and intensity are available on the Monochrome Adapter, ì
  333. but color is interpreted as shown below:
  334.  
  335.         Attribute Byte Setting          Monochrome Shows
  336.            white-on-black                  normal
  337.            black-on-white                  reverse video
  338.            blue-on-black                   underlining
  339.            black-on-black                  nothing
  340.  
  341.  
  342. The format of the attribute byte is presented below.  A bit value ì
  343. of 1 activates a feature, while 0 turns it off.
  344.  
  345.                Bit Number
  346.                     7         Blinking foreground
  347.                     6         Red background
  348.                     5         Green background
  349.                     4         Blue background
  350.                     3         Intensity foreground
  351.                     2         Red foreground
  352.                     1         Green foreground
  353.                     0         Blue foreground
  354. .pa
  355. èA frequently used attribute setting is 14 (hex 0E), which ì
  356. produces an intensified yellow over a black background.  Turbo ì
  357. Pascal includes a set of 16 predefined constants for designating ì
  358. colors, which you may find helpful.  See page 161 of the version ì
  359. 3.0 manual for details.  
  360.  
  361. Boosters' Set Attribute (SetAtt) procedure gives you easy control ì
  362. over the character attributes.  With SetAtt, you can set attributes ì
  363. in blocks as small as a single character or as large as the entire 
  364. screen.  
  365. .pa
  366. è                       SECTION 2 - GROUND RULES
  367.  
  368.  
  369.  
  370. HEAP I/O
  371.  
  372. Heap I/O describes a programming technique that consists of building 
  373. or modifying screen displays on a page of the heap, then copying the 
  374. page to video memory.  For programs targeted to both monochrome and 
  375. color monitor systems, this technique provides a common approach to 
  376. fast screen output.  The steps involved are:
  377.  
  378.         STEP                            TURBO/BOOSTERS EXAMPLE
  379.                                              
  380.         1.  Mark current top            Mark ( HeapTop );
  381.   
  382.         2.  Allocate pages              For i := 1 to Npage do
  383.                                            New ( Page[i] );
  384.  
  385.         3.  Build screens               
  386.             a.  Initially               FillHeap ( page[1], ... ); 
  387.                                         BoxHeap  ( page[1], ... );
  388.                                         (*  and so on  *)
  389.  
  390.             b.  Modify existing         SaveScreen ( page[1] );
  391.                 screen                  MblkHeap   ( page[1], ... );
  392.                                         (*  perhaps more  *)
  393.  
  394.   
  395.         4.  Display any page            RestoreScreen ( page[1] );
  396.   
  397.         5.  Release heap memory         Release ( HeapTop );
  398.             when finished
  399.  
  400. Boosters has a number of routines that assist programmers in 
  401. developing sophisticated screen displays on the heap.  With one 
  402. exception, each heap routine is a clone of some other Boosters 
  403. routine.  
  404.  
  405. For example, procedure Calendar, which generates and displays a 
  406. calendar for any month and year, has a corresponding heap routine 
  407. called CalHeap.  Both routines are identical except for the address of 
  408. their output.  Calendar sends its results to video memory, while 
  409. CalHeap places its output on a specified page of the heap.  
  410. .pa
  411. è        NOTE: All heap routines have as their first argument
  412.               the page of the heap to which output is sent. 
  413.               The remaining arguments match those of their     
  414.               corresponding video routine one-for-one.
  415.  
  416.               Thus, in the case of Calendar and CalHeap, their
  417.               statements might appear as:
  418.  
  419.               Calendar ( 11, 1985, 30, 10 );
  420.               CalHeap  ( page[1], 11, 1985, 30, 10 );
  421.  
  422. To view the results of CalHeap, of course, we must eventually copy 
  423. page[1] to video memory, an operation which RestoreScreen performs 
  424. almost instantly.
  425.  
  426. The one heap routine that has no Boosters clone is FillHeap, which is 
  427. useful for initializing a page of heap memory quickly.  FillHeap is 
  428. similar to Turbo Pascal's FillChar but differs in that it treats the 
  429. heap as having the character/attribute nature of video memory.  Please
  430. see section 3 for details on FillHeap.
  431.  
  432. The following table pairs Boosters video routines with their 
  433. corresponding heap routines.  Please remember that heap memory must 
  434. first be allocated (via New) before it can be used.
  435.  
  436.              Video              Heap            Purpose
  437.  
  438.              CopyBlk            CblkHeap        Copies a video block
  439.              MoveBlk            MblkHeap        Moves  a video block
  440.              SetAtt             HeapAt          Set block attributes
  441.              PutStr             PutHeap         Writes a string
  442.              GetStr             GetHeap         Reads a string
  443.              Calendar           CalHeap         Creates a calendar
  444.              Boxul              BoxHeap         Draws a box
  445.              FindStr            FstrHeap        Finds a string
  446. .pa
  447. è
  448.                                SECTION 3
  449.  
  450.                    DESCRIPTIONS OF BOOSTERS ROUTINES
  451.  
  452.  
  453.  
  454.  
  455. The examples in this section can be found on the Boosters 
  456. distribution diskette.  The file names begin with an X.  The 
  457. routine for PutStr, for instance, is named XPutStr.  
  458.  
  459.  
  460.  
  461. A SUGGESTION
  462.  
  463. If you are new to Boosters, you might find it helpful to run 
  464. the example programs as you read about them.  Make sure 
  465. BoDecl.pas and all the Boosters .pas files (PutStr.pas, 
  466. GetStr.pas, etc.) are on the default drive and directory when 
  467. you run the examples.  Because the examples are generally 
  468. simple, the routines they implement are easy to understand.  
  469.  
  470. Please pay particular attention to the uses of Heap I/O 
  471. ( XBoxUl.pas, XFillHep.pas ).  
  472. .pa
  473. è                                 BODECL
  474.  
  475.  
  476. Purpose:     Declarations for Boosters Utilities.
  477.  
  478. Const
  479.    H  = 'H';                  (*  Code for horizontal PutStr & GetStr *)
  480.    V  = 'V';                  (*  "    "   vertical   "      " "      *)
  481.    StartElapsed : Boolean = FALSE;
  482.                               (*  Initial value for timer function    *)
  483.    Npage = 2;                 (*  Number of heap pages                *)
  484.  
  485. Type
  486.    AnyString   =  string[255];
  487.    HeapBuf     = ^AnyBuf;
  488.    AnyBuf      =  Record
  489.                      Screen : array[1..4000] of byte;
  490.                   end;
  491.    ColumnType  =  1..80;      (* With $R directive active, *)
  492.    RowType     =  1..25;      (* keeps video routines in line *)
  493.    result      =  Record
  494.                      AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer;
  495.                   end;
  496.  
  497. Var
  498.    TimeElapsed,               (* Used by Timer . . . *)
  499.    SaveElapsed,               (* "    "  "           *)
  500.    Ecode,                     (* "    "  Exec for error return *)
  501.    I                          (* the ubiquitous index variable  *)
  502.                      : Integer;
  503.    SaveX                      (*  handy for saving WhereX result *)
  504.                      : ColumnType;
  505.    SaveY                      (*  "     "   "      WhereY "      *)
  506.                      : RowType;
  507.    Xheap             : ColumnType;
  508.    Yheap             : RowType;
  509.    HeapTop           : ^Integer;  (*  for marking current top of heap *)
  510.  
  511.    Ch                         (*  as in read(Kbd,ch) after KeyPressed *)
  512.                      : Char;
  513.    Page                       (*  screens for Heap I/O                *)
  514.                      : array[1..Npage] of HeapBuf;
  515.  
  516.    VideoStatus       : byte   absolute $0000:$0449;
  517.    MonoBuffer        : AnyBuf absolute $B000:0000;
  518.    GraphicsBuffer    : AnyBuf absolute $B800:0000;
  519.    Regs              : Result;
  520.  
  521.    S,                         (*  general string array *)
  522.    FileDesc,                  (*  File name and extension for EXEC *)
  523.    ComLine                    (*  Command Line setting for EXEC    *)
  524.                      : AnyString;
  525. .pa
  526. è                                 BOXUL
  527.  
  528.  
  529. Declaration: Procedure BoxUL ( X1 : ColumnType;
  530.                                Y1 : RowType;
  531.                                X2 : ColumnType;
  532.                                Y2 : RowType; 
  533.                                Style,
  534.                                Attribute : Integer); 
  535.  
  536. Purpose:     Draws a box (rectangle) in a given style with sides
  537.              in specified attribute.
  538.  
  539.              Notes:
  540.              1.  X1,Y1 and X2,Y2 designate the coordinates of the ì
  541.                  upper left and lower right corners, ì
  542.                  respectively, of the box to be drawn.
  543. ì
  544.              2.  Style is a value from 1 to 4 that controls   ì
  545.                  which set of box drawing characters to use.
  546.                     
  547.                  Style = 1 for single lines on all sides.
  548.                  Style = 2 for double lines on all sides.
  549.                  Style = 3 for double-lined vertical sides
  550.                            and single-lined horizontal sides.
  551.                  Style = 4 for single-lined vertical sides
  552.                            and double-lined horizontal sides.
  553.  
  554.              3.  The area enclosed by the box is not ì
  555.                  initialized.
  556.  
  557.              4.  A box must have at least 3 columns and 3 rows.
  558.  
  559. .pa
  560. èExample:     Draw concentric boxes with Boxul then with Heap I/O.
  561.  
  562.              (*$IBoDecl   *)
  563.              (*$IPutStr   *)
  564.              (*$ICopies   *)
  565.              (*$IFillHeap *)
  566.              (*$IPutHeap  *)
  567.              (*$IRestores *)
  568.              (*$IBoxHeap  *)
  569.              (*$IBoxul    *)
  570.  
  571.              BEGIN
  572.  
  573.                 ClrScr;
  574.                 PutStr ( h, 'USING BOXUL', 35, 12, 14 );
  575.                 for i := 0 to 8 do
  576.                    boxul ( 5 + (3*i), 2+i, 75 - (3*i), 23-i ,
  577.                            Random(4)+1, Yellow );
  578.                 ClrScr;
  579.                 Mark ( HeapTop );
  580.                 New ( Page[1] );
  581.                 FillHeap ( Page[1], 1,1,80,25,#32,14 );
  582.                 for i := 0 to 8 do
  583.                    boxHeap ( page[1], 5 + (3*i), 2+i, 75 - (3*i), 23-i ,
  584.                              Random(4)+1, Yellow );
  585.                 RestoreScreen ( page[1] );
  586.                 PutStr ( h, 'USED BOXHEAP', 35, 12, 14 );
  587.                 Release ( HeapTop );
  588.  
  589.              END (* XBoxul *) .
  590.  
  591. .pa
  592. è                                 CALENDAR
  593.  
  594.  
  595. Declaration: Procedure Calendar ( MM, CCYY, X, Y : Integer ); 
  596.  
  597. Purpose:     Generates a calendar for month MM of year CCYY,
  598.              then displays it with upper-left coordinates X,Y.
  599.  
  600.              Notes:
  601.              1.  The calendar size is 22 columns, 15 rows.
  602.  
  603.              2.  The calendar display includes trailing days from ì
  604.                  the previous month and the first days of the ì
  605.                  following month.
  606.  
  607.              3.  CALHEAP generates calendars on a page of the 
  608.                  heap.ì
  609.  
  610. Example:     Display the U.S.A. Bicentennial month.  
  611.  
  612.  
  613.              (*$IBodecl   *)
  614.              (*$IPutStr   *)
  615.              (*$IStrip    *)
  616.              (*$ICopies   *)
  617.              (*$IBoxul    *)
  618.              (*$IDows     *)
  619.              (*$ICenter   *)
  620.              (*$ICalendar *)
  621.  
  622.              BEGIN
  623.  
  624.                ClrScr;
  625.                Calendar ( 7, 1976, 29, 5 );
  626.  
  627.              END (* XCalenda *) .
  628. .pa
  629. è                                  CENTER
  630.  
  631.  
  632. Declaration: Function Center ( S : AnyString; 
  633.                                N : Integer;
  634.                              Pad : Char ) : AnyString;
  635.  
  636. Purpose:     Returns a string of length N with S centered in it.
  637.              Pad is added as necessary to fill out length.
  638.  
  639.  
  640.              Notes:
  641.              1.  AnyString is Type string[255].
  642.                                                        
  643.              2.  If length(S) > N, then the first N characters ì
  644.                  are returned.
  645.  
  646. Example:     Center numbers 1 through 8 within 10-byte fields 
  647.              on first line of screen.
  648.  
  649.              (*$IBoDecl *)
  650.              (*$ICenter *)
  651.              (*$IPutStr *)
  652.  
  653.              BEGIN
  654.  
  655.                 for i := 1 to 8 do
  656.                 begin
  657.                    str ( i, S );
  658.                    PutStr ( h, Center ( S, 10, ' '),
  659.                                1 + (i-1) * 10, 1, 112 );
  660.                 end;
  661.                 read;
  662.  
  663.              END (* XCenter *) .
  664.  
  665. .pa
  666. è                                  COPIES
  667.  
  668.  
  669. Declaration: Function Copies ( C : Char;
  670.                                N : Integer ) : AnyString;
  671.  
  672. Purpose:     Returns N concatenated copies of C.
  673.  
  674.              Notes:
  675.              1.  AnyString is Type string[255].
  676.              2.  See CopyStr for concatenating strings.
  677.  
  678. Example:     Add vertical columns to the Center example.
  679.  
  680.              (*$IBoDecl *)
  681.              (*$ICenter *)
  682.              (*$IPutStr *)
  683.              (*$ICopies *)
  684.  
  685.              BEGIN
  686.                 ClrScr;
  687.                 for i := 1 to 8 do
  688.                 begin
  689.                    str ( i, S );
  690.                    PutStr ( h, Center ( S, 10, ' '), 
  691.                             1 + (i-1) * 10, 1, 112 );
  692.  
  693.                    PutStr ( v, Copies ( #179,24),
  694.                             1 + (i-1) * 10, 2, 14 );
  695.                 end;
  696.                 read;
  697.  
  698.              END (* XCenter *) .
  699. .pa
  700. è                                 COPYBLK
  701.  
  702.  
  703. Declaration: Procedure CopyBlk ( X1 : ColumnType;
  704.                                  Y1 : RowType;
  705.                                  X2 : ColumnType;
  706.                                  Y2 : RowType;
  707.                                  X3 : ColumnType;
  708.                                  Y3 : RowType ) ;
  709.  
  710. Purpose:     Copies block at screen location X1,Y1 (upper left)               ì
  711.              and X2,Y2 (lower right) to screen location beginning
  712.              at upper left coordinates X3,Y3.
  713.  
  714.  
  715. Example:     Create a box and copy it, first with CopyBlk, then 
  716.              with Heap I/O. 
  717.  
  718.              (*$IBoDecl   *)
  719.              (*$IPutStr   *)
  720.              (*$ICopies   *)
  721.              (*$IBoxul    *)
  722.              (*$ICopyBlk  *)
  723.              (*$ICblkHeap *)
  724.              (*$ISaves    *)
  725.              (*$IRestores *)
  726.  
  727.              BEGIN
  728.  
  729.                 Mark ( HeapTop );
  730.                 New ( page[1] );
  731.  
  732.                 ClrScr;
  733.                 Boxul   ( 1, 1, 18, 10, 1, Yellow );
  734.                 CopyBlk ( 1, 1, 18, 10, 1, 12 );
  735.                 SaveScreen ( page[1] );
  736.                 read;
  737.                 for i := 1 to 3 do
  738.                 begin
  739.                    CopyBlk ( 1, 1, 18, 10, 21+(i-1)*20, 1 );
  740.                    CopyBlk ( 1, 1, 18, 10, 21+(i-1)*20, 12 );
  741.                 end;
  742.                 read;
  743.                 ClrScr;
  744.                 read;
  745.  
  746.                 for i := 1 to 3 do
  747.                 begin
  748.                    CblkHeap ( page[1], 1, 1, 18, 10, 21+(i-1)*20, 1 );
  749.                    CblkHeap ( page[1], 1, 1, 18, 10, 21+(i-1)*20, 12 );
  750.                 end;
  751.                 RestoreScreen ( page[1] );
  752.                 Release ( HeapTop );
  753.              END (* XCopyBlk *) .
  754. è                                 COPYSTR
  755.  
  756.  
  757. Declaration: Function CopyStr ( S : AnyString;
  758.                                 N : Integer ) : AnyString;
  759.  
  760. Purpose:     Returns N concatenated copies of S.
  761.  
  762.              Notes:
  763.              1.  AnyString is Type string[255]. 
  764.              2.  See Copies for concatenating characters.
  765.  
  766. Example:     Section the screen.
  767.  
  768.              (*$IBoDecl  *)
  769.              (*$IPutStr  *)
  770.              (*$ICopies  *)
  771.              (*$ICopyStr *)
  772.  
  773.              Procedure BoCells ( y : RowType );
  774.              var
  775.                 Spacer : AnyString;
  776.                 N      : Integer;
  777.              begin
  778.                 S := Copies(#196,9)+#197;
  779.                 PutStr ( h, CopyStr ( S,8 ), 1, y, 14 );
  780.                 Spacer :=   CopyStr ( '         '+#179, 8);
  781.                 for  n := 1 to 5 do
  782.                    PutStr ( h, Spacer, 1, y+n, 14 );
  783.              end;
  784.  
  785.              BEGIN
  786.  
  787.                 ClrScr;
  788.                 BoCells ( 1 );
  789.                 BoCells ( 6 );
  790.                 BoCells ( 11 );
  791.                 BoCells ( 16 );
  792.                 BoCells ( 21 );
  793.                 Read;
  794.  
  795.              END (* XCopyStr *) .
  796. .pa
  797. è
  798.                              CURSOR ROUTINES
  799.  
  800.  
  801. Declaration: Procedure CursorOff;
  802.              Procedure CursorOn;
  803.                     ì
  804.  
  805. Purpose:     CursorOff hides the cursor, CursorOn makes it ì
  806.              visible.           ì
  807.  
  808. Example:     Turn the cursor off, then turn it on when user   ì
  809.              strikes the Enter key.
  810.  
  811.              (*$IBoDecl *)
  812.              (*$ICursor *)
  813.              (*$IPutStr *)
  814.              (*$ICopies *)
  815.              (*$IBoxul  *)
  816.  
  817.              BEGIN
  818.  
  819.                 ClrScr;
  820.                 CursorOff;
  821.                 Boxul (30,8,50,16,3,14);
  822.                 PutStr (h, 'Press RETURN',34,10,14);
  823.                 PutStr (h, 'to get cursor',33,12,14);
  824.                 PutStr (h, 'BACK',38,14,14);
  825.                 read;
  826.                 CursorOn;
  827.  
  828.              END (* XCursor *) .
  829.  
  830. .pa
  831. è                                   DOWS
  832.  
  833.  
  834. Declaration: Function Dows ( MM, DD, CCYY : Integer) : AnyString;
  835.                     ì
  836.  
  837. Purpose:     Returns day of the week (Sunday, Monday, etc.) forì
  838.              any valid date.    ì
  839.  
  840.              Notes:
  841.              1.  MM and DD must be within usual ranges for month ì
  842.                  and day.  CCYY is 4-digit year (e.g., 1980, not ì
  843.                  80).
  844.  
  845. Example:     Compute day of the week for user input.  Pressing ì
  846.              return at the prompt ends session.
  847.  
  848.              (*$IBoDecl *)
  849.              (*$IDows   *)
  850.              (*$IPutStr *)
  851.              (*$IStrip  *)
  852.  
  853.              var
  854.                 mm, dd, ccyy, len : integer;
  855.  
  856.              BEGIN
  857.  
  858.                 ClrScr;
  859.                 Repeat
  860.                    PutStr (h,'Enter the numeric value for any '+
  861.                       'month, day and year',1,1,14);
  862.                    PutStr (h,'separated by spaces: ',1,2,14);
  863.                    ClrEol;
  864.                    read ( s );
  865.                    if length(s) > 0 then
  866.                    begin
  867.                       s   := strip ( S, ' ');
  868.                       len := pos(' ',S) - 1;
  869.                       val (copy (s,1,len),mm,ecode);
  870.                       s := copy (s,len+2,50);
  871.                       len := pos(' ',s) - 1 ;
  872.                       val (copy (S,1,len),dd,ecode);
  873.                       len := length(s) - pos(' ',s);
  874.                       val (copy (S,length(s)-len+1,len),ccyy,ecode);
  875.                       if ccyy < 100 then
  876.                          ccyy := ccyy + 1900;
  877.                       PutStr (h,'Day of the week is '+
  878.                                  dows(mm,dd,ccyy),1,4,14); 
  879.                    end;
  880.                 until length(s) = 0;
  881.  
  882.              END (* XDows *) .
  883. .pa
  884. è                                   EXEC
  885.  
  886.  
  887. Declaration: Procedure Exec ( FileDescription,
  888.                               CommandLine : AnyString;
  889.                               Ecode       : Integer); 
  890.  
  891. Purpose:     Loads another program into memory and executes it,
  892.              then returns control to the invoking program.
  893.  
  894.              Notes:
  895.              1.  This is only available when issued from
  896.                  a .COM file under Turbo Pascal release 3.0.
  897.  
  898.              2.  FileDesc contains the drive, directory, file
  899.                  name and extension of the program to
  900.                  execute.
  901.  
  902.              3.  CommandLine specifies the DOS command line
  903.                  that Exec will pass to the command processor
  904.                  for execution.
  905.  
  906.              4.  Ecode = 0, execution was successful.
  907.                  Ecode = 1, improper parameters.
  908.  
  909.  
  910. Example 1:   Format a disk on the B: drive
  911.  
  912.              (*$IBoDecl *)
  913.              (*$IExec   *)
  914.  
  915.              BEGIN
  916.                 FileDesc := 'COMMAND.COM';
  917.                 ComLine  := 'COMMAND /C FORMAT B:';
  918.  
  919.                 Exec (FileDesc, CommandLine, Ecode);
  920.              END.
  921.  
  922.  
  923. Example 2:   Execute the Norton Utilities' DiskLook (C). 
  924.  
  925.              (*$IBoDecl *)
  926.              (*$IExec   *)
  927.  
  928.              BEGIN
  929.                 Filedesc := 'command.com';
  930.                 ComLine := 'command /c DL B:';
  931.  
  932.                 Exec (FileDesc, ComLine, Ecode);
  933.  
  934.                 Write(' Hello from Boosters');
  935.              END.
  936. .pa
  937. èExample 3:   Execute Turbo Pascal (C).
  938.  
  939.              (*$IBoDecl *)
  940.              (*$IExec   *)
  941.  
  942.              BEGIN
  943.  
  944.                 Filedesc := 'B:TURBO.COM';
  945.                 Exec (FileDesc, ComLine, Ecode);
  946.                 Write(' Hello from Boosters');
  947.  
  948.              END (* XExec *) .
  949. .pa
  950. è                              FILLHEAP
  951.  
  952.  
  953.  
  954. Declaration: Procedure FillHeap ( Page : HeapBuf;
  955.                                     X1 : ColumnType;
  956.                                     Y1 : RowType;
  957.                                     X2 : ColumnType;
  958.                                     Y2 : RowType;
  959.                                      C : Char;
  960.                                      A : Integer);
  961.  
  962. Purpose:     Generates characters C with video attribute A on Page 
  963.              of the heap, from (X1,Y1) to (X2,Y2).
  964.  
  965.              Notes:
  966.              1.  FillHeap is useful for initializing a page on the heap.
  967.  
  968. Example:     Generate and display alphabet screens A - Z.
  969.  
  970.              (*$IBoDecl   *)
  971.              (*$IRestores *)
  972.              (*$IFillHeap *)
  973.  
  974.              BEGIN
  975.  
  976.                 Mark ( HeapTop );
  977.                 New ( Page[1] );
  978.                 for i := 1 to 26 do
  979.                 begin
  980.                    FillHeap ( Page[1], 1, 1, 80, 25,
  981.                               Chr(64+i), 7 );
  982.                    RestoreScreen ( Page[1] );
  983.                    delay(150);
  984.                 end;
  985.                 Release ( HeapTop );
  986.  
  987.              END (* XFillHep *) .
  988. .pa
  989. è                               FINDSTR
  990.  
  991.  
  992. Declaration: Procedure FindStr (  X : ColumnType;
  993.                                   Y : RowType;
  994.                               VAR S : AnyString;
  995.                                   N ,
  996.                               Ecode : Integer);  
  997.  
  998. Purpose:     Search for S in video memory, beginning at (X,Y).
  999.              If S found, cursor is placed at offset N from S and 
  1000.              Ecode is set to zero.  Ecode is one when S is not 
  1001.              found.
  1002.  
  1003.              Notes:
  1004.              1.  For N > 0, offset is calculated from end of S.
  1005.                  Cursor will be positioned at length(S) + N.
  1006.                  For instance, for N = 1, the cursor will be 
  1007.                  placed at S[length(S)+1].
  1008.  
  1009.              2.  For N = 0, the cursor is placed at S[1].
  1010.  
  1011.              3.  For N < 0, offset is calculated from beginning
  1012.                  of S.  Cursor will be placed at S[1] + (-N).
  1013.                  Given N = -1, the cursor will be positioned at
  1014.                  the display coordinate immediately preceding ì
  1015.                  S[1].
  1016.  
  1017.              4.  If the value of N is such that it would place the ì
  1018.                  cursor offscreen, FindStr places the cursor at ì
  1019.                  either the beginning of the display screen or at ì
  1020.                  the end, whichever is closer to S.
  1021.  
  1022.              5.  FindStr's heap clone is FstrHeap.  
  1023.                  
  1024.                  Procedure FstrHeap ( Page : HeapBuf;
  1025.                                      VAR S : AnyString;
  1026.                                  VAR Xheap : ColumnType;
  1027.                                  VAR Yheap : RowType;
  1028.                                          N , 
  1029.                                      Ecode : Integer); 
  1030.                                      external 'FstrHeap.com';
  1031.                  
  1032.                  With FstrHeap, the search always begins at (1,1)
  1033.                  on the heap.  If S is found, Xheap and Yheap are
  1034.                  set and ecode = 0.  For S not found, ecode = 1.
  1035.                  See BoDemo.pas for uses of FstrHeap.
  1036. .pa
  1037. èExample:     Demonstrate string find capability.
  1038.  
  1039.  
  1040.              (*$IBoDecl  *)
  1041.              (*$IFindStr *)
  1042.              (*$IGetStr  *)
  1043.              (*$IPutStr  *)
  1044.  
  1045.              BEGIN
  1046.  
  1047.                 Randomize;
  1048.                 ClrScr;
  1049.                 PutStr (v,'I AM VERTICAL',Random(80)+1,1,7);
  1050.                 FindStr (1,1,'I',0,Ecode);
  1051.                 GetStr (v,S,0,0,13);
  1052.                 read;                                          
  1053.                 insert ('NO LONGER ',S,6);
  1054.                 PutStr (h,S,1,15,14);
  1055.  
  1056.              END (* XFindStr *) . 
  1057. .pa
  1058. è
  1059.                                   GETSTR
  1060.  
  1061.  
  1062. Declaration: Procedure GetStr (  HV : Char;
  1063.                               VAR S : AnyString;
  1064.                                   X : ColumnType;
  1065.                                   Y : RowType;
  1066.                                 LEN : Integer);
  1067.  
  1068. Purpose:     Loads contents of video memory into S, beginning 
  1069.              at coordinates X,Y for length LEN.
  1070.  
  1071.              Notes:
  1072.              1.  Direction of read operation is set by HV, which 
  1073.                  will be horizontal when HV = 'H', vertical when 
  1074.                  HV = 'V'.  Constants H and V are set in
  1075.                  Boosters Declaration File (BoDecl). 
  1076.  
  1077.              2.  If X and Y are both zero, read operation begins 
  1078.                  at current position.
  1079.  
  1080.              3.  GETHEAP is the Heap I/O clone of GetStr.  With
  1081.                  GetHeap, X and Y cannot be zero, nor is there any
  1082.                  positioning of the cursor.
  1083.  
  1084.  
  1085. Example:     Write and read a column of vertical text.
  1086.  
  1087.              (*$IBoDecl *)
  1088.              (*$IGetStr *)
  1089.              (*$IPutStr *)
  1090.  
  1091.              BEGIN
  1092.  
  1093.                 ClrScr;
  1094.                 PutStr (v,'I AM VERTICAL',1,1,7);
  1095.                 GetStr (v,S,1,1,13);
  1096.                 read;
  1097.                 insert ('NO LONGER ',S,6);
  1098.                 PutStr (h,S,1,15,14);
  1099.  
  1100.              END (* XGetStr *) .  
  1101. .pa
  1102. è                               LEFT
  1103.  
  1104.  
  1105. Declaration: Function Left ( S : AnyString;
  1106.                            LEN : Integer;
  1107.                            PAD : Char) : AnyString;
  1108.  
  1109.  
  1110. Purpose:     Left-justifies and pads (if necessary) S in theì
  1111.              result. ì
  1112.  
  1113.  
  1114. Example:     Create a sample input form.
  1115.  
  1116.              (*$IBoDecl *)
  1117.              (*$ILeft   *)
  1118.              (*$IPutStr *)
  1119.  
  1120.              BEGIN
  1121.  
  1122.                 ClrScr;
  1123.                 PutStr (h,left('Name ',60,'_'),5,1,14);
  1124.                 PutStr (h,left('Street ',60,'_'),5,2,14);
  1125.                 PutStr (h,left('City, State, and Zip ',60,'_'),
  1126.                         5,3,14);
  1127.                 read;
  1128.  
  1129.              END (* XLeft *) .
  1130. .pa
  1131. è                              MOVEBG
  1132.  
  1133. Declaration: Procedure MoveBg (  Page  :  HeapBuf;
  1134.                                    X1  :  ColumnType;
  1135.                                    Y1  :  RowType;
  1136.                                    X2  :  ColumnType;
  1137.                                    Y2  :  RowType;
  1138.                                    X3  :  ColumnType;
  1139.                                    Y3  :  RowType);
  1140.  
  1141. Purpose:     Moves the block at X1,Y1 (upper left) and
  1142.              X2,Y2 (lower right) of the current screen
  1143.              to block beginning at X3,Y3 (upper left) oε page.
  1144.                                       
  1145.              Notes:
  1146.              1.  When MoveBg is called, the block at X1,Y1,X2,Y2
  1147.                  is saved on the stack, the screen defined by ì
  1148.                  page is copied to video memory, then the block ì
  1149.                  on the stack is written to the screen.
  1150.  
  1151. Example:     Overlay some boxes, then move one from the other
  1152.              incrementally.
  1153.  
  1154.              (*$IBoDecl *)
  1155.              (*$IScreen *)
  1156.              (*$IPutStr *)
  1157.              (*$ICopies *)
  1158.              (*$IBoxul  *)
  1159.              (*$ISetAtt *)
  1160.              (*$IMoveBg *)
  1161.  
  1162.              BEGIN
  1163.                 Mark ( HeapTop );
  1164.                 New ( page[1] );
  1165.                 ClrScr;
  1166.                 Boxul ( 20, 8, 37, 16, 1, 14);
  1167.                 for i := 9 to 15 do
  1168.                    PutStr ( h, Copies ( '▓',16),21, i, 14);
  1169.                 SetAtt ( 38, 9, 40, 17, 30);
  1170.                 SetAtt ( 21, 17, 40, 17, 30);
  1171.                 Read;
  1172.                 SaveScreen ( page[1] );
  1173.                 Boxul ( 20, 8, 37, 16, 1, 14);
  1174.                 for i := 9 to 15 do
  1175.                    PutStr ( h, Copies('▒',16),21, i, 7);
  1176.                 Read;
  1177.                 for i := 1 to 16 do
  1178.                 begin
  1179.                    Movebg ( page[1], 20+(i-1)*2, 8, 40+(i-1)*2, 17, 
  1180.                             22+(i-1)*2, 8 );
  1181.                    delay(04);
  1182.                 end;
  1183.                 Release( HeapTop );
  1184.              END (* XMoveBg *) .
  1185. è                               MOVEBLK
  1186.  
  1187.  
  1188. Declaration: Procedure MoveBlk ( X1  :  ColumnType;
  1189.                                  Y1  :  RowType;
  1190.                                  X2  :  ColumnType;
  1191.                                  Y2  :  RowType;
  1192.                                  X3  :  ColumnType;
  1193.                                  Y3  :  RowType);
  1194.  
  1195.  
  1196. Purpose:     Moves the block defined by X1,Y1,X2,Y2 (upper-
  1197.              left and lower-right coordinates) to location
  1198.              X3,Y3 (upper-left).
  1199.  
  1200.              
  1201.              Notes:
  1202.              1.  The original block (X1,Y1,X2,Y2) is saved onì
  1203.                  the stack, erased from video memory, then copied 
  1204.                  to (X3,Y3).  By contrast, see CopyBlk description. 
  1205.              2.  To move blocks on the heap, use MblkHeap.
  1206.  
  1207. Example:     Relocate three boxes.
  1208.  
  1209.              (*$IBoDecl  *)
  1210.              (*$IMoveBlk *)
  1211.              (*$IPutStr  *)
  1212.              (*$ICopies  *)
  1213.              (*$IBoxul   *)
  1214.  
  1215.              BEGIN
  1216.  
  1217.                 ClrScr;
  1218.                 BoxUl ( 1,1, 8, 7,3,14);
  1219.                 BoxUl ( 10,1,17, 7,3,14);
  1220.                 BoxUl ( 19,1,26, 7,3,14);
  1221.                 PutStr (h,'Press enter to move boxes',1,9,14);
  1222.                 read;
  1223.                 MoveBlk (1,1,26,7,1,12);
  1224.  
  1225.              END (* XMoveBlk *) .
  1226. .pa
  1227. è.fi boref2.pas
  1228.